<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
         html body{
           
            background-image: url(img./bg.jpeg);
         }
        .login-box {
            width: 500px;
            height: 600px;
            margin: 100px auto;
            background-color: white;
        }

        .login-box .title {
            font-weight: bold;
            line-height: 80px;
            text-align: center;
            background-color: rgb(95, 95, 245);
            color: white;
        }

        .login-box .block {
           width: 300px;
           margin: 20px auto;

        }

        .login-box .block input {
            height: 40px;
            padding-left: 20px;
            border: 1px solid #ccc;
            border-radius: 5px;
            width: 100%;
            outline: none;
            box-sizing: border-box;
            
        }
        .login-box .zuce input{
            background-color: green;
            width: 80px;
            margin-left: 100px;
            color: white;
        }
      
        span{
            margin-left: 100px;
            color: #ccc;
            font-size: 12px;
        }
    </style>
</head>

<body>
    <div class="login-box">
        <div class="title">注册页</div>
        <div class="block">
            <input type="text" placeholder="输入用户名">
        </div>
        <div class="block">
            <input type="password" placeholder="输入密码">
        </div>
        <div class="block">
            <input type="password" placeholder="确认密码">
        </div>
        <div class="block">
            <input type="text" placeholder="输入邮箱">
        </div>
        <span>已有帐号去登陆</span>
        <div class="block zuce">
            <input type="button" value="注册">
        </div>
    </div>
</body>

</html>
<script src="./js/ajax.js"></script>
<script>
    var inputs = document.querySelectorAll('.login-box .block input');
    console.log(inputs);
    inputs[4].onclick = function () {
        if (inputs[0].value && inputs[1].value) {
            if (/^\d{4}$/.test(inputs[1].value)) {
                ajax('get', 'https://yantianfeng.com/api/register', {
                    username: inputs[0].value,
                    password: inputs[1].value,
                    password: inputs[2].value,
                    email: inputs[3].value
                }, function (data) {
                    console.log(data);
                })
            }else{
                alert('输入正确用户名和密码')
            }

        }else{
            alert('账户和密码不能为空')
        }
    }

</script>